home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / AddButtons.c next >
C/C++ Source or Header  |  2000-05-09  |  6KB  |  214 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/AddButtons.c,v 41.11 2000/05/09 20:33:07 mlemos Exp $
  3.  *
  4.  * AddButtons.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1994 Paul Weterings.
  8.  * All Rights Reserved.
  9.  *
  10.  * Modified by Ian J. Einman, 4/26/96
  11.  *
  12.  * $Log: AddButtons.c,v $
  13.  * Revision 41.11  2000/05/09 20:33:07  mlemos
  14.  * Bumped to revision 41.11
  15.  *
  16.  * Revision 1.2  2000/05/09 19:58:29  mlemos
  17.  * Merged with the branch Manuel_Lemos_fixes.
  18.  *
  19.  * Revision 1.1.2.3  1999/08/01 03:56:35  mlemos
  20.  * Added missing disposal of removed buttons.
  21.  *
  22.  * Revision 1.1.2.2  1999/07/28 16:40:19  mlemos
  23.  * Fixed the code that attempted to remove a button that failed to be inserted
  24.  * by simply disposing the object.
  25.  *
  26.  * Revision 1.1.2.1  1998/02/28 17:44:45  mlemos
  27.  * Ian sources
  28.  *
  29.  *
  30.  */
  31.  
  32. /*
  33. dcc AddButtons.c -mi -ms -mRR -proto -lbgui
  34. quit
  35. */
  36.  
  37. #include "DemoCode.h"
  38.  
  39. /*
  40.  *      Object ID's. Please note that the ID's are shared
  41.  *      between the menus and the gadget objects.
  42.  */
  43. #define ID_ADD          21
  44. #define ID_QUIT         22
  45. #define ID_INS          23
  46. #define ID_REM          24
  47.  
  48. /*
  49.  *      Simple menu strip.
  50.  */
  51. struct NewMenu SimpleMenu[] = {
  52.    Title( "Project" ),
  53.       Item( "Add",        "A", ID_ADD ),
  54.       Item( "Insert",     "I", ID_INS ),
  55.       Item( "Remove all", "R", ID_REM ),
  56.       ItemBar,
  57.       Item( "Quit",       "Q", ID_QUIT ),
  58.    End
  59. };
  60.  
  61. /*
  62.  *      Simple button creation macros.
  63.  */
  64. #define AddButton\
  65.    ButtonObject,\
  66.       LAB_Label,              "Added",\
  67.       LAB_Style,              FSF_BOLD,\
  68.       FuzzButtonFrame,\
  69.    EndObject
  70.  
  71. #define InsButton\
  72.    ButtonObject,\
  73.       LAB_Label,              "Inserted",\
  74.       LAB_Style,              FSF_BOLD,\
  75.       FuzzButtonFrame,\
  76.    EndObject
  77.  
  78.  
  79. VOID StartDemo( void )
  80. {
  81.    struct Window           *window;
  82.    Object                  *WO_Window, *GO_Add, *GO_Quit, *GO_Ins, *GO_Rem, *addobj[20], *base;
  83.    ULONG                    signal = 0, rc;
  84.    BOOL                     running = TRUE, ok = FALSE;
  85.    int                      x = 0, xx;
  86.  
  87.    /*
  88.     *      Create window object.
  89.     */
  90.    WO_Window = WindowObject,
  91.       WINDOW_Title,           "Add/Insert Demo",
  92.       WINDOW_MenuStrip,       SimpleMenu,
  93.       WINDOW_LockHeight,      TRUE,
  94.       WINDOW_AutoAspect,      TRUE,
  95.       WINDOW_AutoKeyLabel,    TRUE,
  96.       WINDOW_MasterGroup,
  97.          base = HGroupObject,
  98.             StartMember, GO_Add  = FuzzButton( "_Add",        ID_ADD  ), EndMember,
  99.             StartMember, GO_Ins  = FuzzButton( "_Insert",     ID_INS  ), EndMember,
  100.             StartMember, GO_Rem  = FuzzButton( "_Remove all", ID_REM  ), EndMember,
  101.             StartMember, GO_Quit = FuzzButton( "_Quit",       ID_QUIT ), EndMember,
  102.          EndObject,
  103.       EndObject;
  104.  
  105.         /*
  106.          *      OK?
  107.          */
  108.    if ( WO_Window )
  109.    {
  110.       /*
  111.        *      Open window.
  112.        */
  113.       if ( window = WindowOpen( WO_Window ))
  114.       {
  115.          /*
  116.           *      Get signal mask.
  117.           */
  118.          GetAttr( WINDOW_SigMask, WO_Window, &signal );
  119.          do {
  120.             /*
  121.              *      Poll messages.
  122.              */
  123.             Wait( signal );
  124.             while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
  125.             {
  126.                switch ( rc )
  127.                {
  128.                case WMHI_CLOSEWINDOW:
  129.                case ID_QUIT:
  130.                   /*
  131.                    *      Bye now.
  132.                    */
  133.                   running = FALSE;
  134.                   break;
  135.  
  136.                case ID_ADD:
  137.                   if ( x == 19 )
  138.                   {
  139.                      Tell( "Max Nr. of gadgets\n" );
  140.                      break;
  141.                   }
  142.                   x++;
  143.  
  144.                   addobj[x]  = AddButton;
  145.  
  146.                   ok = DoMethod( base, GRM_ADDMEMBER, addobj[ x ],
  147.                      LGO_FixMinHeight, FALSE,
  148.                      LGO_Weight,       DEFAULT_WEIGHT,
  149.                      TAG_END );
  150.  
  151.                   if (!ok)
  152.                   {
  153.                      DisposeObject(addobj[ x ]);
  154.                      x--;
  155.                      Tell( "Last object did not fit!\n" );
  156.                   }
  157.  
  158.                   if ( ! window )
  159.                      goto error;
  160.                   break;
  161.  
  162.                case ID_REM:
  163.                   if ( x > 0 )
  164.                   {
  165.                      for ( xx = 1; xx <= x; xx++ )
  166.                      {
  167.                         DoMethod( base, GRM_REMMEMBER, addobj[ xx ] );
  168.                         DisposeObject(addobj[ xx ]);
  169.                      }
  170.                      x = 0;
  171.                   }
  172.                   else
  173.                      Tell("Were out of gadgets!\n");
  174.                   break;
  175.  
  176.                case ID_INS:
  177.                   if ( x == 19 )
  178.                   {
  179.                      Tell( "Max Nr. of gadgets\n" );
  180.                      break;
  181.                   }
  182.                   x++;
  183.  
  184.                   addobj[x]  = InsButton;
  185.  
  186.                   ok = DoMethod( base, GRM_INSERTMEMBER, addobj[ x ], GO_Rem,
  187.                      LGO_FixMinHeight, FALSE,
  188.                      LGO_Weight,       DEFAULT_WEIGHT,
  189.                      TAG_END );
  190.  
  191.                   if (!ok)
  192.                   {
  193.                      DisposeObject(addobj[ x ]);
  194.                      x--;
  195.                      Tell( "Last object did not fit!\n" );
  196.                   }
  197.  
  198.                   if ( ! window )
  199.                      goto error;
  200.                   break;
  201.  
  202.                }
  203.             }
  204.          } while ( running );
  205.       }
  206.       else
  207.          Tell( "Could not open the window\n" );
  208.       error:
  209.       DisposeObject( WO_Window );
  210.    }
  211.    else
  212.       Tell( "Could not create the window object\n" );
  213. }
  214.